package com.yang.doctorrecruitment.action;

import com.alibaba.fastjson.JSONObject;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.yang.doctorrecruitment.dao.UserResumeDAO;
import com.yang.doctorrecruitment.dto.JobIntension;
import com.yang.doctorrecruitment.utils.NullChange;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

public class JobIntensionAction extends ActionSupport {
    public JobIntension jobintension;

    public JobIntension getJobintension() {
        return jobintension;
    }

    public void setJobintension(JobIntension jobintension) {
        this.jobintension = jobintension;
    }

    public String JobIntension(){
        int Salay= jobintension.getSalary();
        String WorkAddress= NullChange.NullChange(jobintension.getWorkAddress());
        String WorkName=NullChange.NullChange(jobintension.getWorkName());
        int WorkKind=jobintension.getWorkKind();

        //进行存储,先转换成json
        JSONObject json=new JSONObject();
        json.put("Salay",Salay);
        json.put("WorkAddress",WorkAddress);
        json.put("WorkName",WorkName);
        json.put("WorkKind",WorkKind);
        String jsonString =json.toJSONString();

        //需要拿到UserID
        ActionContext ac=ActionContext.getContext();
        Map session=ac.getSession();
        String UserID= (String) session.get("UserID");
        System.out.println(jobintension.getSalary());
        System.out.println(jobintension.getWorkAddress());
        System.out.println(jobintension.getWorkKind());
        System.out.println(jobintension.getWorkName());
        boolean res= UserResumeDAO.updataJobIntension(jsonString,UserID);
        HttpServletRequest request= (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
        if(res){

            request.setAttribute("tipMessage",1);
            return SUCCESS;
        }else{
            request.setAttribute("tipMessage",2);
            return ERROR;
        }
    }

}
